# -*- coding: utf-8 -*-
# created on 2016/5/9

import re
from mathsolver.functions.base import BaseFuncName
from mathsolver.functions.hanshu.compute import HanShuCompute
from mathsolver.functions.root import BasicJisuan
from mathsolver.functions.sympy_utils import get_all_child

POW2 = [4, 9, 16, 25, 36, 49, 86, 81, 100]


class JiSuan(BasicJisuan):
    """
    jisuan().solver(BasePoly("2*sin((pi*45/180))-(1)/(sqrt(2)-1)+(sin((pi*^/180)))**(2)+(sin((pi*^/180)))**(2)"))
    jisuan().solver(BasePoly("log(6,2)-log(3,2)"))
    jisuan().solver(BasePoly("(sqrt(3)+sqrt(2))*(sqrt(2)+2)"))
    jisuan().solver(BasePoly("(sqrt(5)+sqrt(6))*(sqrt(5)-sqrt(6))"))
    jisuan().solver(BasePoly("(sqrt(2) - 3)**2 + 2/3*sqrt(18)"))
    jisuan().solver(BasePoly("Abs(-2)+ 4**(2/2)- (2/3)**0"))
    jisuan().solver(BasePoly("10**4/2"))
    """
    def func_compute(self, expr):
        sub_func = get_all_child(expr, lambda x: "__" in x.__class__.__name__)
        for sub in sub_func:
            name, var = str(sub).split("__", 1)
            var = re.search("\\((.*)\\)", var).group(1)
            stepsolver = HanShuCompute(known=self.known).solver(BaseFuncName({"name": name, "var": var, "type": type}))
            self.steps.extend(stepsolver.steps)
            expr = expr.subs({sub: stepsolver.output[0].value})
        return expr.evalf()


if __name__ == '__main__':
    pass
